package com.jacobson.core.framework.errorhandler

import android.content.Context

/**
 * ================================================
 *
 *  @author Wucz on 2018/7/24 11:13
 * ================================================
 */
class RxErrorHandler private constructor(
        private val context: Context,
        private val onErrorListener: OnErrorListener
) {

    fun handleError(e: Throwable) {
        onErrorListener.onError(context, e)
    }

    class Builder {
        private var context: Context? = null
        private var onErrorListener: OnErrorListener? = null

        fun context(context: Context): Builder {
            this.context = context
            return this
        }

        fun onErrorListener(listener: OnErrorListener): Builder {
            this.onErrorListener = listener
            return this
        }

        fun build() = RxErrorHandler(context!!, onErrorListener!!)
    }
}